<?php

$doc = document::getInstance();
prefs::getInstance()->setPref("theme", "default");

// placeholder debugger
$doc->addJS("styles/js/debug.js");

$doc->addJS("styles/js/flash.js", true);

// add theme specific css & js
$doc->addJS("theme/".prefs::getInstance()->getPref("theme")."/js/theme.js");
$doc->addCSS("theme/".prefs::getInstance()->getPref("theme")."/css/theme.css");	

?>

<noscript>
<div class="message fatal last">
<h1>Javascript error</h1>
<p>Please enable JavaScript to view this website. <a href="http://www.google.com/support/adsense/bin/answer.py?hl=nl&amp;answer=12654">Read how</a>.</p>
</div>
</noscript>

<?php 
/**
 * Meebo bar
 */

if (config::getInstance()->meebo) { ?>
<script type="text/javascript">
if (typeof Meebo == 'undefined') {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){
	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'meebo_network_here'});
Meebo('makeEverythingSharable');
}
</script>
<?php }

/**
 * Prefs in JSON
 */

// breaks in chrome (safari?): Uncaught SyntaxError: Unexpected token default
if (1==2) { ?>
<script type="text/javascript">
	var prefs = {
	<?php echo "\t"; foreach (prefs::getInstance()->getPrefs() as $key => $value) {
		if ($value == "true" || $value == "false" || is_numeric($value)) {
			echo $key . ": " . $value . ", ";
		} else {
			echo $key . ": '" . $value . "', ";
		}
	} ?>
	};
</script>
<?php }

/**
 * Menu templates
 */
$req = new request(array("module" => "sitemap", "action" => "menu"));
module::loadToPosition($req, "menu"); 	
?>
<div id="menu">
	<?php echo $doc->contents["menu"]; ?>
</div>
<?php
 
/**
 * Main templates
 */
echo $doc->contents["main"];

/**
 * Debugger
 */
$config = config::getInstance();
if ($config->debug) {
	$req = new request(array("module" => "debug", "action" => "vars"));
	module::loadToPosition($req, "debug", css::FLOAT_CLEAR); 	
	echo $doc->contents["debug"];
} ?>

<div id="flash"></div>
<div id="modal-bg"></div>
<div id="modal"><div></div><a href="javascript:flash.modalClose();">OK</a></div>

<?php if ($_SERVER["HTTP_HOST"] == "www.example.com") { ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-CODE-HERE");
pageTracker._setDomainName(".example.com");
pageTracker._trackPageview();
} catch(err) {}</script>
<?php } ?>

<?php if (config::getInstance()->meebo) { ?>
<script type="text/javascript">
 	Meebo("domReady");
</script>
<?php } ?>

<?php if (config::getInstance()->uservoice) { ?>
<script type="text/javascript">
  var uservoiceOptions = {
    key: 'key_here',
    host: 'host_here.uservoice.com', 
    forum: 'code_here',
    alignment: 'right',
    background_color:'#C8F800', 
    text_color: 'black',
    hover_color: '#D20000',
    lang: 'en',
    showTab: true
  };
  function _loadUserVoice() {
    var s = document.createElement('script');
    s.src = ("https:" == document.location.protocol ? "https://" : "http://") + "uservoice.com/javascripts/widgets/tab.js";
    document.getElementsByTagName('head')[0].appendChild(s);
  }
  _loadSuper = window.onload;
  window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };
</script>
<?php } ?>